package com.mall.user.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.mall.user.entity.param.RoleAddParam;
import com.mall.user.entity.param.RoleEditParam;
import com.mall.user.entity.po.Role;
import com.mall.user.entity.vo.RoleVO;
import com.mall.user.mapper.RoleMapper;
import com.mall.user.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wuyijie
 * @since 2021-06-20
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public RoleVO add(RoleAddParam roleAddParam) {
        RoleVO add = null;
        roleMapper.insert(BeanUtil.toBean(roleAddParam, Role.class));
        add = BeanUtil.toBean(roleAddParam, RoleVO.class);
        return add;
    }

    @Override
    public int deleteById(int id) {
        int delete;
        delete = roleMapper.deleteById(id);
        return delete;
    }

    @Override
    public RoleVO edit(RoleEditParam roleEditParam) {
        RoleVO edit = null;
        roleMapper.updateById(BeanUtil.toBean(roleEditParam, Role.class));
        edit = BeanUtil.toBean(roleEditParam, RoleVO.class);
        return edit;
    }

    @Override
    public RoleVO queryById(int id) {
        RoleVO roleVO = null;
        Role role = roleMapper.selectById(id);
        roleVO = BeanUtil.toBean(role, RoleVO.class);
        return roleVO;
    }
}
